package com.android.hedgehog;

import java.util.List;
import java.util.Random;

import android.graphics.Color;

import com.android.hedgehog.framework.Game;
import com.android.hedgehog.framework.Graphics;
import com.android.hedgehog.framework.Screen;
import com.android.hedgehog.framework.Input.TouchEvent;

public class ModeMenu extends Screen {
	Graphics graphics;
	int puzzleNumber;
	String[] puzzleTitles = { "Math", "Card", "Goalie", "TimeBomb","SeeSaw" };
	Random rand = new Random();
	int currentTopScore;

	public ModeMenu(Game game, int puzzle) {
		super(game);
		puzzleNumber = puzzle;
		graphics = game.getGraphics();
		currentTopScore = Settings.highScores[puzzleNumber][0];
	}

	@Override
	public void update(float deltaTime) {
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		game.getInput().getKeyEvents();
		int len = touchEvents.size();

		for (int i = 0; i < len; i++) {
			TouchEvent event = touchEvents.get(i);
			if (event.type == TouchEvent.TOUCH_UP) {

				if (event.x > 40 && event.x < 280 && event.y > 80 && event.y < 150) {// EASY
					playSound(1);
					game.setScreen(new FreePlayScreen2(game, puzzleNumber, 0));
				}
				if (event.x > 40 && event.x < 280 && event.y > 160 && event.y < 230) {// NORMAL
					playSound(1);
					game.setScreen(new FreePlayScreen2(game, puzzleNumber, 1));
				}
				if (event.x > 40 && event.x < 280 && event.y > 240 && event.y < 310) {// HARD
					playSound(1);
					game.setScreen(new FreePlayScreen2(game, puzzleNumber, 2));
				}

				if (event.x < 50 && event.y > 430) { // if back button
					playSound(1);
					game.setScreen(new FreePlayMenu2(game));
					return;
				}

			}
		}

	}

	@Override
	public void present(float deltaTime) {
		graphics.drawBackground(Color.BLACK);
		graphics.drawUniversalText(puzzleTitles[puzzleNumber], 2, true, 160, 50, 30, 255,Color.WHITE);

		for (int i = 0; i < 3; i++) {
			graphics.drawUniversalRect(40, 80 + (80 * i), 239, 70, false, false, 3, 255, Color.WHITE); // rectangle
			if (i == 0) {
				graphics.drawUniversalText("EASY", 2, true, 160, 140, 40, 255, Color.BLUE);
			}
			if (i == 1) {
				graphics.drawUniversalText("NORMAL", 2, true, 160, 220, 40, 255, Color.MAGENTA);
			}
			if (i == 2) {
				graphics.drawUniversalText("HARD", 2, true, 160, 300, 40, 255, Color.GREEN);
			}

		}

		graphics.drawUniversalText("Top Score: " + currentTopScore, 2, true, 160, 460, 16, 255,
				Color.argb(255, rand.nextInt(255), rand.nextInt(255), rand.nextInt(255)));

		graphics.drawRect(0, 430, 50, 50, Color.WHITE); // back

	}

	private void playSound(int soundNum) {
		if (!Settings.soundEnabled)
			return;
		if (soundNum == 1)
			Assets.bitten.play(1);

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

}
